#include "MTList.hpp"
#include "MTExpression.hpp"
#include <string>
#include <iostream>
#include <sstream>
#include "MTDouble.hpp"
#include "Params.h"

namespace MathematicaTranslator
{
	std::string* MTList::generateCode(CodeGenContext& context)
	{
		std::ostringstream ss;

		ss << " = { ";

		for (int i = 0; i < listElements->size(); i++)
		{
			ss << * (*listElements)[i]->generateCode(context);
			if (i < listElements->size() - 1) ss << ", ";
		}
		ss << " }";

		#ifdef DEBUG
			std::cout<<"List definition created" <<std::endl;
		#endif

		return new std::string(ss.str());
	}
	std::string* MTList::getType()
	{
		std::string* type = new std::string("");
	
		for(int i = 0; i < listElements->size(); i++)
		{
			std::string* currentType = listElements->at(i)->getType();
			if( *currentType == "int" && *type != "float" )
			{
				*type = "int";
			} else if(*currentType == "float")
			{
				*type = "float";
			} else if(*currentType == "double")
			{
				*type = "double";
				break;
			}
		}
		return type;
	}

	std::string* MTList::getNumberOfElements()
	{
		std::ostringstream ss;
		ss << listElements->size();

		return new std::string(ss.str());
	}
	
	int MTList::getClassType(){
		return LIST;
	}

}